<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <div id="app"></div>
    <!-- 1.引入依赖 -->
    <script src="../react/react.development.js"></script>
    <script src="../react/react-dom.development.js"></script>
    <script src="../react/babel.min.js"></script>
    <!-- 2.开始开发 -->
    <script type="text/babel">
      class App extends React.Component {
        constructor() {
          super()

          this.state = {
            isLogin: true,
          }
        }

        render() {
          let { isLogin } = this.state
          let message = null
          if (isLogin) {
            message = '退出登录'
          } else {
            message = '登录'
          }
          return (
            <div>
              {isLogin && <div>欢迎登录吴亦凡</div>}
              {/* 1.通过bind来改变this指向 */}
              <button onClick={this.btnClick.bind(this)}>{message}</button>
              {/* 2.通过ES6 filed 来绑定this */}
              <button onClick={this.btnClick2}>{message}</button>

              {/* 3.通过箭头函数调用,手动调用事件 */}
              <button onClick={e => {this.btnClick3('jean')}}>{message}</button>
            </div>
          )
        }

        btnClick(e) {
          this.setState({
            isLogin: !this.state.isLogin
          })
        }

        btnClick2 = e => {
          this.setState({
            isLogin: !this.state.isLogin
          })
        }

        btnClick3(name) {
          alert(name)
          this.setState({
            isLogin: !this.state.isLogin
          })
        }

      }
      ReactDOM.render(<App />, document.getElementById('app'))
    </script>
  </body>
</html>
